#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{
    int pd = open("love.txt",O_RDONLY); // 打开文件
    if(pd == -1){

        perror("错误1");
        return -1;
    }

    int pd2 = open("love6.txt",O_WRONLY|O_APPEND|O_CREAT,0664);
    if (pd2 == -1)
    {
        close(pd);
        perror("错误2");
        return -1;
    }

char buff[1024];
ssize_t buf_len = 0;
while ((buf_len = read(pd,buff,sizeof(buff)))>0)
{
    write(pd2,buff,buf_len);
    write(STDOUT_FILENO,buff,buf_len);
}

if(buf_len == -1)
{
    close(pd);
    close(pd2);
    perror("错误3");
    return -1;
}
    close(pd);
    close(pd2);

    return 0;
}
